<?php

namespace App\Http\Controllers\Home\Tool;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Contract\FuncsContract;
use App\Funcs\Curl;
class MetailController extends Controller
{
    public function index(Request $request){
        $city = $request->input('city');
        $date = $request->input('date');
        $mid = $this->getList($city,$date);
        $res = $this->getDetail($mid);
        return view('home.tool.metail.index',['res'=> $res]);
    }
    public function getList($city,$date){
        $url = "http://www.feipinjia.com/metalPriceList.htm";
        $res = Curl::post($url,array('city' =>$city,'createDate'=>$date));
        $arr = array();
        preg_match("/priceInfo(?:\()'(.*?)\'/",$res , $arr);
        return $arr[1];
    }
    public function getDetail($mid){
        $detailUrl = "http://www.feipinjia.com/metalPriceSingle.htm?mid=".$mid;
        $detail = Curl::get($detailUrl);
        $detailArr = array();
        preg_match("/<div class=\"Main4LeftContent\">(.*?)<\/div>/ism",$detail , $detailArr);
        return $detailArr[1];
    }

}
